<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>留言板2</title>
    <script src="./vue.js"></script>
    <style>
        h2,
        p {
            margin: 0;
        }

        .box {
            margin: 30px auto;
            width: 300px;
        }

        #user,
        #message {
            box-sizing: border-box;
            width: 300px;
            border: 1px solid #000;
            padding: 10px;
            height: 100px;
            resize: none;
            display: block;
        }

        #user {
            padding: 0 10px;
            height: 30px;
            margin-bottom: 10px;
        }

        #btn {
            display: block;
            margin: 10px auto;
            width: 60%;
            height: 40px;
        }

        #list {
            border-top: 1px solid #000;
            padding: 10px 0 0;
            margin: 0;
            list-style: none;
        }

        #list li {
            position: relative;
            font: 14px/30px "宋体";
            border-bottom: 1px solid #000;
            padding: 0 15px;
            overflow: hidden;
        }

        .clos {
            position: absolute;
            right: 5px;
            top: 10px;
        }

        .clos2 {
            position: absolute;
            right: 5px;
            top: 30px;
        }

        /* .replay{
    position:absolute;
    right: 5px;
    top: 35px;
} */
        .mask {
            width: 100vw;
            height: 100vh;
            background: black;
            opacity: .3;
            position: absolute;
            left: 0;
            top: 0;
            display: none;
        }

        .comfirm {
            width: 200px;
            height: 120px;
            background: white;
            text-align: center;
            position: absolute;
            left: 50%;
            top: 30%;
            border-radius: 5px;
            transform: translate(-50%, -50%);
            overflow: hidden;
            display: none;

        }

        .comfirm button {
            /* position: absolute; */
            /* right: 10px; */
            float: right;
            margin-top: 20px;
            margin-right: 10px;
        }

        
    </style>
</head>

<body>
    <div class="box">
        <input type="text" id="user" v-model="inpVal.name" />
        <textarea id="message" v-model="inpVal.content">我就是传说中的无敌小明</textarea>

        <button id="btn" @click="sub">提交留言</button>

        <ul id="list">
            <!-- 循环数组，实时渲染 -->
            <li style="height: auto" v-for="(item,key) in arr">
                <h2 class="user">{{item.name}}说:</h2>
                <p>{{item.content}}</p>
                <p v-for="val in arr1">{{val.content}}</p>

                <div class="replay" v-show="flag">
                    <input type="text" v-model="answer.content"/><button @click="ans">确定</button>
                </div>

                <a href="javascript:;" class="clos" @click="dele(key)">删除</a>
                <a href="javascript:;" class="clos2" @click="rep(key)">回复</a>
            </li>
            <!-- <li style="height: auto">
            <h2 class="user">老师说:</h2>
            <p>小明滚出去</p>
            <p>回复的内容</p>
            <a href="javascript:;" class="clos">删除</a>
        </li> -->
        </ul>

    </div>
    <script>

        // 实例化vue框架
        let vm = new Vue({
            // 确定html中vue框架的作用范围
            el: ".box",
            data: {

                flag:false,
                arr: [],
                inpVal: {
                    name: "",
                    content: "",
                },

                arr1:[],
                answer:{
                    content:"",
                }

            },
            // 所有事件函数对象
            methods: {
                sub: function () {
                    let inpVal2 = {
                        name: this.inpVal.name,
                        content: this.inpVal.content,
                    }
                    this.arr.push(inpVal2);
                },
                dele: function (key) {
                    // 删除相对key值（下标）的数组里的对象
                    this.arr.splice(key, 1);
                },
                rep:function(key){
                    this.flag=!this.flag;
                    console.log(key);
                },
                ans(){
                    // console.log(this.answer.content);
                    let answer1 = {
                        content:this.answer.content,
                    };
                    this.arr1.push(answer1);
                }
            },
        })
    </script>
</body>

</html>